<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>选择直播间</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-body" pad15>
						<div class="layui-form layui-col-md12" style="text-align:right;padding-bottom:10px">
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
						</div>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
	var nowtime = {:time()};
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{:url('index')}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
			//{type:"checkbox"},
      {field: 'id', title: 'ID',  sort: true,width:80},
      {field: 'roomId', title: '房间号',width:100},
      {field: 'name', title: '直播间信息',templet:function(d){
				html = '';
				html+='		<img src="'+d.shareImg+'" style="max-width:100px;float:left"/>';
				html+='			<div style="float: left;width:200px;margin-left: 10px;white-space:normal;line-height:20px;">';
				html+='				<div style="width:100%;color:#333;font-size:16px">';
				html+= 					d.name;
				html+= '			</div>';
				html+='				<div style="color:green;padding-top:5px;">开播：'+date('Y-m-d H:i:s',d.startTime)+'</div>';
				html+='				<div style="color:#999">结束：'+date('Y-m-d H:i:s',d.endTime)+'</div>';
				html+='				<div style="color:#666">主播：'+d.anchorName+'</div>';
				html+='			</div>';
				return html;
      },width:380},
      //{field: 'goodsdata', title: '直播间商品',width:240},
      {field: 'live_status', title: '直播状态',templet:function(d){
				html = '';
				/*
				if(d.live_status==101){
					html+='<span style="color:green">直播中</span>';
				}else if(d.live_status==102){
					html+='<span style="color:#333">未开始</span>';
				}else if(d.live_status==103){
					html+='<span style="color:#aaa">已结束</span>';
				}else if(d.live_status==104){
					html+='<span style="color:red">禁播</span>';
				}else if(d.live_status==105){
					html+='<span style="color:red">暂停中</span>';
				}else if(d.live_status==106){
					html+='<span style="color:red">异常</span>';
				}else if(d.live_status==107){
					html+='<span style="color:#aaa">已过期</span>';
				}
				return html;
				*/
				if(d.startTime > nowtime ) return '<span style="color:#333">未开始</span>';
				if(d.startTime < nowtime && d.endTime >= nowtime){
					return '<span style="color:green">进行中</span>';
				}
				if(d.endTime < nowtime) return '<span style="color:#aaa">已结束</span>';
				return '';
			}},
			//{field: 'status', title: '列表显示',templet:function(d){
			//	if(d.status==0){
			//		return '<span style="color:red">未开启</span>';
			//	}else if(d.status==1){
			//		return '<span style="color:green">已开启</span>';
			//	}
      //}},
      {field: 'operation', title: '操作',templet: '<div><button class="table-btn" onclick="chooseliveroom(\'{{d.id}}\')">选择</button></div>',align:'center'}
    ]]
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	function chooseliveroom(id){
		var index = layer.load();
		$.post("{:url('getliveroominfo')}",{id:id},function(res){
			layer.close(index);
			window.parent.chooseliveroom(res.data,"{$Request.param.args}");
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});
	}
	</script>
</body>
</html>